package sol.leetcode;

import java.util.*;

/**
 * Two Sum
 */
public class Issue001 {
    public int[] twoSum(int[] nums, int target) {
        Map<Integer, Integer> map = new HashMap<Integer, Integer>();
        int[] res = null;

        for (int i = 0; i < nums.length; ++i) {
            if (map.containsKey(nums[i])) {
                res = new int[]{map.get(nums[i]), i};
            } else
                map.put(target - nums[i], i);
        }
        return res;
    }

    public static void main(String[] args) {
        int[] nums = {2, 7, 11, 15};
        int target = 9;
        System.out.println(Arrays.toString(new Issue001().twoSum(nums, target)));
    }
}
